<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="fragments :: head(~{::title})">
    <Title>博客详情</Title>
</head>

<body>
<!-- 导航 -->
    <nav th:replace="fragments::menu(-1)"></nav>

    <!-- 中间内容 -->
    <div id="waypoint" class="me-padded-tb-large  animated fadeIn">
        <div class="ui container">
            <div class="ui top attached segment">
                <div class="ui grid">
                    <!-- 用户基本信息 -->
                    <div class="eleven wide column">
                        <div class="ui mini horizontal link list">
                            <div class="item">
                                <img src="../static/image/1.png" alt="" class="ui avatar image">
                                <div class="content">
                                    <a href="#">
                                        <div class="header">杨瑞卿</div>
                                    </a>
                                </div>

                            </div>
                            <div class="item" >
                                <i class="calendar icon"></i>  <span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm:ss')}">2020-3-26</span>
                            </div>
                            <div class="item">
                                <i class="eye icon"></i> <span th:text="${blog.views}">9999</span>
                            </div>
                        </div>
                    </div>
                    <!-- 标签label -->
                    <div class="right aligned five wide column">
                        <a href="#" class="ui basic teal label me-padded-mini">努力的Coder_yrq</a>
                    </div>
                </div>
            </div>
            <div class="ui attached segment">
                <!-- 图片 -->
                <img src="https://i.picsum.photos/id/999/800/450.jpg" th:src="${blog.firstPicture}"  alt="" class="ui image fluid rounded">
            </div>
            <div class="ui attached padded segment js-toc-content">

                <!-- 内容 -->
                <div class="ui right aligned basic segment">
                    <div class="ui orange basic label" th:text="${blog.flag.length()}!=0?${blog.flag}:'原创'">原创</div>
                </div>

                <h2 class="ui center aligned header" th:text="${blog.title}">生命里的遇见，都是命中注定</h2>
                <div id="content" class="typo typo-selection js-toc-content me-padded-lr-responsive me-padded-tb-large" th:utext="${blog.content}">
                </div>

                <!-- 标签 -->
                <div class="me-padded-lr" >
                    <div class="ui teal basic left pointing label me-marrgin-tb-tiny" th:each=" tag:${blog.tags}">
                        <span th:text="${tag.name}"> 数据结构与算法</span>
                    </div>
                </div>

                <!-- 打赏 -->
                <div class="ui center aligned basic segment " th:if="${blog.isAppreciation()}">
                    <button id="payButton" class="ui orange basic circular button">赞赏</button>
                </div>
                <div class="ui payQR flowing popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <div class="image">
                                <img src="../static/image/wechatPay.png" alt="" class="ui rounded bordered image"
                                     style="width: 120px;">
                                <div>微信</div>
                            </div>
                            <div class="image">
                                <img src="../static/image/AirPay.png" alt="" class="ui rounded bordered image"
                                     style="width: 120px;">
                                <div>支付宝</div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <!-- 博客信息 作者说明 以及版权声明-->
            <div class="ui attached positive message">
                <div class="ui middle aligned grid">
                    <div class="eleven wide column">
                        <div class="list">
                            <li th:text="|作者- ${blog.user.nickname}|">作者：杨瑞卿</li>
                            <li th:text="|发表时间- ${#dates.format(blog.createTime, 'yyyy-MM-dd HH:mm:ss')}|" >发表时间：2020-3-21 14:04</li>
                            <li th:text="|更新时间- ${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm:ss')}|" >更新时间：2020-3-21 14:04</li>
                            <li>版权声明：自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)</li>
                        </div>
                    </div>
                    <div class="five wide column">
                        <img src="../static/image/wechat.png" alt="" class="ui rounded bordered image right floated"
                             style="width: 110px;">
                    </div>
                </div>
            </div>

            <div class="ui bottom attached segment" th:if="${false}">
                <!-- 留言区 -->
                <div id="comment-container" class="ui teal segment">
                    <div class="ui minimal comments">
                        <h3 class="ui dividing header">留言区</h3>
                        <div class="comment">
                            <a class="avatar">
                                <img src="../static/image/2.jpg">
                            </a>
                            <div class="content">
                                <a class="author">Matt</a>
                                <div class="metadata">
                                    <span class="date">Today at 5:42PM</span>
                                </div>
                                <div class="text">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="../static/image/2.jpg">
                            </a>
                            <div class="content">
                                <a class="author">Elliot Fu</a>
                                <div class="metadata">
                                    <span class="date">Yesterday at 12:30AM</span>
                                </div>
                                <div class="text">
                                    <p>This has been very useful for my research. Thanks as well!</p>
                                </div>
                                <div class="actions">
                                    <a class="reply">Reply</a>
                                </div>
                            </div>
                            <div class="comments">
                                <div class="comment">
                                    <a class="avatar">
                                        <img src="../static/image/2.jpg">
                                    </a>
                                    <div class="content">
                                        <a class="author">Jenny Hess</a>
                                        <div class="metadata">
                                            <span class="date">Just now</span>
                                        </div>
                                        <div class="text">
                                            Elliot you are always so right :)
                                        </div>
                                        <div class="actions">
                                            <a class="reply">Reply</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="../static/image/2.jpg">
                            </a>
                            <div class="content">
                                <a class="author">Joe Henderson</a>
                                <div class="metadata">
                                    <span class="date">5 days ago</span>
                                </div>
                                <div class="text">
                                    Dude, this is awesome. Thanks so much
                                </div>
                                <div class="actions">
                                    <a class="reply">Reply</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 输入区-->
                <!-- ajax 请求表单   -->
                <div id="comment-form" class="ui reply form">
                    <input type="hidden" name="blog.id" th:value="${blog.id}">
                    <input type="hidden" name="parentComment.id" value="-1">
                    <div class="field">
                        <textarea placeholder="请输入评论信息..."></textarea>
                    </div>
                    <div class="fields ">
                        <div class="field  me-mobile-wide me-marrgin-bottom-mini">
                            <div class="ui left icon input">
                                <i class="user icon"></i>
                                <input type="text" name="nickname" placeholder="姓名">
                            </div>
                        </div>
                        <div class="field  me-mobile-wide me-marrgin-bottom-mini">
                            <div class="ui left icon input">
                                <i class="mail icon"></i>
                                <input type="text" name="email" placeholder="邮箱">
                            </div>
                        </div>
                        <div class="field  me-mobile-wide me-marrgin-bottom-mini">
                            <button id="commentpost-btn" type="button" class="ui blue labeled submit icon button me-mobile-wide">
                                <i class="icon edit"></i> 发布
                            </button>
                        </div>
                    </div>

                </div>
            </div>


        </div>
    </div>

    <!--    工具条 -->
    <div id="toolbar" class="me-fixed me-right-buttom me-padded-mini" style="display: none !important; ">
        <div class="ui vertical buttons">
            <button id="catalogue" type="button" class="ui teal  button">目 录</button>
            <a href="#comment-container" class="ui teal  button">留 言</a>
            <a class="ui wechat icon button"><i class="weixin icon"></i></a>
            <a class="ui qq icon button"><i class="qq icon"></i></a>
            <button class="ui icon button"><i class="weibo icon"></i></button>
            <button onclick="location.href='https://github.com/1193700079/blog_yrq'" class="ui icon button"><i class="github icon"></i></button>
            <div  id="toTop-button" class="ui  icon button">
                <i class="chevron up icon"></i>
            </div>
        </div>
    </div>

    <!-- 目录生成 -->
    <div class="ui catalogue-container popup flowing  transition hidden" style="width: 250px;">
        <ol class="js-toc">

        </ol>
    </div>

    <div id="qrcode_wechat"  class="ui wechat_qr popup flowing transition hidden" style="width: 130px;">
    </div>

    <div class="ui qq_qr popup flowing transition hidden" style="width: 130px;">
        <img src="../static/image/qq.jpg" alt="" class="ui rounded image" style="width: 100px;">
    </div>

    <!-- 底部栏 -->
    <footer th:replace="fragments::footer"></footer>

<!-- 引入js脚本 -->
<!--/*/<th:block th:replace="fragments :: script">/*/-->
<!--/*/</th:block>/*/-->

    <script>
        var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function(direction) {
            if(direction=="down"){
                $("#toolbar").show(500);
            }else{
                $("#toolbar").hide(500);
            }
            console.log('Scrolled to waypoint!' + direction)
        }
        });

        //平滑滚动
        $("#toTop-button").click(function(){
            $(window).scrollTo(0,500);
        });

        // 自动生成二维码
        var qrcode = new QRCode("qrcode_wechat", {
            text: "http://jindo.dev.naver.com/collie",
            width: 128,
            height: 128,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
        });

        $(".qq").popup({
            popup: $(".qq_qr"),
            position: "left center"
        });
        $(".wechat").popup({
            popup: $(".wechat_qr"),
            position: "left center"
        });

        //生成目录
        tocbot.init({
            // Where to render the table of contents.
            tocSelector: '.js-toc',
            // Where to grab the headings to build the table of contents.
            contentSelector: '.js-toc-content',
            // Which headings to grab inside of the contentSelector element.
            headingSelector: 'h1, h2, h3',
            // For headings inside relative or absolute positioned containers within content.
        });

        // 手机端点击显示导航栏
        $(".menu.toggle").click(function () {
            $(".me-item").toggleClass("me-mobile-hide");
        });

        // 打赏按钮  
        $("#payButton").popup({
            popup: $(".payQR.popup"),
            on: 'click',
            position: "bottom center"
        });

        // 目录按钮  
        $("#catalogue").popup({
            popup: $(".catalogue-container"),
            on: 'click',
            position: "left center"
        });

       //评论表单验证
        $('.ui.form').form({
            fields: {
                title: {
                    identifier: 'content',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入评论内容'
                    }
                    ]
                },
                content: {
                    identifier: 'nickname',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入你的大名'
                    }]
                },
                type: {
                    identifier: 'email',
                    rules: [{
                        type: 'email',
                        prompt: '请填写正确的邮箱地址'
                    }]
                }
            }
        });
        $(function () {
            $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/6");
        });

        $('#commentpost-btn').click(function () {
            //检验表单
            var boo = $('.ui.form').form('validate form');
            if (boo) {
                console.log('校验成功');
                postData();
            } else {
                console.log('校验失败');
            }
        });

        function postData() {
            $("#comment-container").load(/*[[@{/comments}]]*/"",{
                "parentComment.id" : $("[name='parentComment.id']").val(),
                "blog.id" : $("[name='blog.id']").val(),
                "nickname": $("[name='nickname']").val(),
                "email"   : $("[name='email']").val(),
                "content" : $("[name='content']").val()
            },function (responseTxt, statusTxt, xhr) {
                //回到首页
                $(window).scrollTo($('#comment-container'),500);
                //清空表单内容
                clearContent();
            });
        }
        function clearContent() {
            $("[name='content']").val('');
            $("[name='parentComment.id']").val(-1);
            $("[name='content']").attr("placeholder", "请输入评论信息...");
        }
        function reply(obj) {
            //注意要用小写
            var commentId = $(obj).data('commentid');
            var commentNickname = $(obj).data('commentnickname');
            $("[name='content']").attr("placeholder", "@"+commentNickname).focus();
            $("[name='parentComment.id']").val(commentId);
            $(window).scrollTo($('#comment-form'),500);
        }

    </script>

</body>

</html>